#include "oiltrans.h"

namespace cores
{
    namespace database
    {
        namespace terminal
        {
            OilTrans *OilTrans::globalInstance = nullptr;

            OilTrans::OilTrans()
            {
                if (OilTrans::globalInstance == nullptr)
                {
                    OilTrans::globalInstance = this;
                }
            }

            OilTrans::~OilTrans()
            {
                if (OilTrans::globalInstance == this)
                {
                    OilTrans::globalInstance = nullptr;
                }
            }

            std::vector<OilTransaction> OilTrans::getRawTransDataS(const bool &is_test)
            {
                if (OilTrans::globalInstance == nullptr)
                    return {};

                return OilTrans::globalInstance->getRawTransData(is_test);
            }

            void OilTrans::addOneTransDataS(const OilTransaction &trans_item)
            {
                if (OilTrans::globalInstance != nullptr)
                    OilTrans::globalInstance->addOneTransData(trans_item);
            }

            void OilTrans::addOneTransDataS(const OilTransaction &trans_item, const uint16_t &serial_num)
            {
                if (OilTrans::globalInstance != nullptr)
                    OilTrans::globalInstance->addOneTransData(trans_item, serial_num);
            }

            void OilTrans::updateTransDataStatusS(const std::vector<std::string> &ids, const bool &is_upload)
            {
                if (OilTrans::globalInstance != nullptr)
                    OilTrans::globalInstance->updateTransDataStatus(ids, is_upload);
            }

            std::vector<SerialNumber> OilTrans::getSerialNumberDataS()
            {
                if (OilTrans::globalInstance != nullptr)
                    return OilTrans::globalInstance->getSerialNumberData();

                return {};
            }

            std::vector<SerialNumber> OilTrans::getSerialNumberDataS(const uint16_t &lora_id, const uint8_t &nozzle_code)
            {
                if (OilTrans::globalInstance != nullptr)
                    return OilTrans::globalInstance->getSerialNumberData(lora_id, nozzle_code);

                return {};
            }

            void OilTrans::addSerialNumberRecordS(const SerialNumber& item)
            {
                if (OilTrans::globalInstance != nullptr)
                    OilTrans::globalInstance->addSerialNumberRecord(item);
            }


            void OilTrans::updateSerialNumberRecordS(const SerialNumber& item)
            {
                if (OilTrans::globalInstance != nullptr)
                    OilTrans::globalInstance->updateSerialNumberRecord(item);
            }

            std::vector<LlqDataItem> OilTrans::getNoUploadLlqDataS(const bool &is_test)
            {
                if (OilTrans::globalInstance != nullptr)
                    return OilTrans::globalInstance->getNoUploadLlqData(is_test);

                return {};
            }


            void OilTrans::addNewLlqDataS(const LlqDataItem &item)
            {
                if (OilTrans::globalInstance != nullptr)
                    OilTrans::globalInstance->addNewLlqData(item);
            }

            void OilTrans::updateLlqDataStatusS(const std::vector<std::string> &ids, const bool &is_upload)
            {
                if (OilTrans::globalInstance != nullptr)
                    OilTrans::globalInstance->updateLlqDataStatus(ids, is_upload);
            }
        }
    }
}
